package cn.zyl.functions;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;


/**
 * Created by weili0677 on 2016/8/6.
 */
public class AppTools {

    public static void startApp(Context context,String appName){
        if (appName==null)
            return;
        if (appName.equals("weixin")){
            startWeixin(context);  //微信
        }else if (appName.equals("QQ")){
            startQQ(context);
        }else if (appName.equals("HeartRate")){  //心率
            startHeartRate(context);
        }else if (appName.equals("Pedometer")){  //计步器
            startPedometer(context);
        }else if (appName.equals("Settings")){  //设置
            startSettings(context);
        }else if (appName.equals("XiaoJing")){  //小鲸
            startYiya(context);
        }else if (appName.equals("FindPhone")){  //查找手机
            startFindPhone(context);
        }else if (appName.equals("Music")){  //音乐
            startMusic(context);
        }else if (appName.equals("Labyrinth")){  //平衡球
            startLabyrinth(context);
        }
    }

    //"com.tencent.tws.watchmusicplayer", "com.danial.labyrinth", "com.tencent.tws.findphone"

    /**
     * 调用微信
     * @param context
     */
    public static void startWeixin(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.wechatagent","com.tencent.tws.wechatagent.contact.ContactActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 调用QQ
     * @param context
     */
    public static void startQQ(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.qqagent","com.tencent.tws.qqagent.ui.ContactListActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 调用心率
     * @param context
     */
    public static void startHeartRate(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.heartrate","com.tencent.tws.heartrate.MainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 调用计步器
     * @param context
     */
    public static void startPedometer(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.pedometer","com.tencent.tws.pedometer.MainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 调用设置
     * @param context
     */
    public static void startSettings(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.android.settings","com.android.settings.MainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 调用小鲸语音
     * @param context
     */
    public static void startYiya(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.yiya.watch","com.tencent.wear.yiya.yiyawearclient.YiyaWatchMainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }
    /**
     * 调用音乐播放器
     * @param context
     */
    public static void startMusic(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.watchmusicplayer","com.tencent.tws.watchmusicplayer.activity.MainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }
    /**
     * 调用查找手机
     * @param context
     */
    public static void startFindPhone(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.tencent.tws.findphone","com.tencent.tws.findphone.MainActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }
    /**
     * 调用平横球
     * @param context
     */
    public static void startLabyrinth(Context context){
        try {
            Intent intent = new Intent();
            ComponentName comp = new ComponentName("com.danial.labyrinth","org.cocos2dx.cpp.EntryActivity");
            intent.setComponent(comp);
            intent.setAction("android.intent.action.MAIN");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }catch (Exception e){
            e.printStackTrace();
            Toast.makeText(context,"app调用失败",Toast.LENGTH_SHORT).show();
        }
    }
}
